const net = require('net');
const chatServer = net.createServer();
// 收集所有接入的客户端
const clientList = [];

chatServer.on("connection", client => {
  client.write("Hi!\n");
  clientList.push(client);
  client.on("data", data => {
    console.log("recieve: ", data.toString());
    clientList.forEach(v => {
      v.write(data);
    });
    
  });
});

chatServer.listen(9000);